package lib;

import java.util.List;

import lib.api.thetvdb.TheTVDBApi;
import lib.api.thetvdb.model.TheTVDBEpisode;
import lib.api.thetvdb.model.TheTVDBSerie;
import lib.model.EpisodeFile;

public class JTheTVDBAdapter{
	
	private final TheTVDBApi jtvapi;
	
	
	public JTheTVDBAdapter(){
		this.jtvapi = new TheTVDBApi("A1720D2DDFDCE82D");
	}
	
	public TheTVDBSerie searchSerie(EpisodeFile episode){
		return this.jtvapi.getSerie(
				this.jtvapi.searchSerie(
						episode.getShow(), 
						null),
				null);
	}
	
	public TheTVDBEpisode getEpisode(EpisodeFile episode){
		return this.jtvapi.getEpisode(
				episode.getTvdbid(),
				episode.getSeason(), 
				episode.getEpisodeNumbers().get(0),
				null);
	}
	
	public TheTVDBSerie getSerie(EpisodeFile episode){
	    if (episode.getTvdbid() > 0){
	        return this.jtvapi.getSerie(
				episode.getTvdbid(),
				null);
	    }else{
	        return this.jtvapi.getSerie(
	                this.jtvapi.searchSerie(episode.getShow(), null), null);
	    }
	    
	}
	
	public List<TheTVDBEpisode> getAllEpisodes(int tvdbid, String language){
		return this.jtvapi.getAllEpisodes(tvdbid, language);
	}
}
